/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       spotlight.cpp
 * Author:     karooolek
 * Created on: 2009-03-27
 *
 **********************************************************************************************************************/

#include "spotlight.h"

namespace mGameEngine
{
namespace Graphics
{

SpotLight::SpotLight() :
    PositionalLight(),
    _direction(),
    _innerCone(M_PI_4), _outerCone(M_PI_2)
{
}

SpotLight::SpotLight(const Color &ambient, const Color &diffuse,
                     const Color &specular,
                     float constantAttenuation, float linearAttenuation,
                     float quadraticAttenuation,
                     float innerCone, float outerCone,
                     const Vector3 &position, const Vector3 &direction) :
    PositionalLight(ambient, diffuse, specular, constantAttenuation,
    linearAttenuation, quadraticAttenuation, position), 
    _direction(direction), _innerCone(innerCone), _outerCone(outerCone)
{
}

SpotLight::~SpotLight()
{
}

void SpotLight::set(uint l) const
{
    if(!_enabled)
    {
        return;
    }

    l += GL_LIGHT0;

    glLightfv(l, GL_AMBIENT, _ambient);
    glLightfv(l, GL_DIFFUSE, _diffuse);
    glLightfv(l, GL_SPECULAR, _specular);
    glLightf(l, GL_CONSTANT_ATTENUATION, _constantAttenuation);
    glLightf(l, GL_LINEAR_ATTENUATION, _linearAttenuation);
    glLightf(l, GL_QUADRATIC_ATTENUATION, _quadraticAttenuation);
    glLightfv(l, GL_POSITION, Vector4(_position));
    glLightfv(l, GL_SPOT_DIRECTION, Vector4(_direction));
    glLightf(l, GL_SPOT_CUTOFF, cosf(0.5f * _outerCone) + 1.0);
    glLightf(l, GL_SPOT_EXPONENT, cosf(0.5f * _innerCone) + 1.0);
}

}
}

